import Vue from 'vue';
import iView from 'iview';
import VueRouter from 'vue-router';
import Routers from './router';
import Util from './libs/util';
import App from './app.vue';
import 'iview/dist/styles/iview.css';

function timestampToTime(timestamp) {
        var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var Y = date.getFullYear() + '-';
        var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        var D = date.getDate() + ' ';
        var h = date.getHours() + ':';
        var m = date.getMinutes() + ':';
        var  s = date.getSeconds();
        return Y+M+D;
    }

function removeTag(str){
	return str.replace(/<\/?.+?>/g,"").replace(/ /g,"")
}
function info(nodesc,content){
       this.$Notice.info({
           title: content,
           desc: nodesc ? '' : 'Here is the notification description. Here is the notification description. '
       });
}

function keyWrodsReplace (keyWord,str) {
	var re = new RegExp(keyWord,"g");
	return str.toString().replace(re,`<span style='background-color:#f90;font-weight: 700;'>${keyWord}</span>`);
}


Vue.prototype.transformTime=timestampToTime;
Vue.prototype.removeTag=removeTag;
Vue.prototype.info=info;
Vue.prototype.keyWrodsReplace=keyWrodsReplace;

Vue.use(VueRouter);
Vue.use(iView);

// 路由配置
const RouterConfig = {
    mode: 'history',
    routes: Routers
};
const router = new VueRouter(RouterConfig);

router.beforeEach((to, from, next) => {
    iView.LoadingBar.start();
    Util.title(to.meta.title);
    next();
});

router.afterEach((to, from, next) => {
    iView.LoadingBar.finish();
    window.scrollTo(0, 0);
});

//bus总线
const Bus = new Vue();
new Vue({
    el: '#app',
    router: router,
    data:{
    	Bus
    },
    render: h => h(App)
});
